package name.huzhenbo.java.patterns.strategy;

/**
 * Take a look at the generic type implementation at name.huzhenbo.java.klass.BubbleSorter
 */
class BubbleSorter {
    private SorterHandler sorterHandler;

    public BubbleSorter(SorterHandler sorterHandler) {
        this.sorterHandler = sorterHandler;
    }

    public void sort() {
        for (int i = sorterHandler.length() - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (sorterHandler.outOfOrder(j)) {
                    sorterHandler.swap(j);
                }
            }
        }
    }
}
